package com.yzy.fly.mapper;

import com.yzy.fly.entity.role.FlyAttribute;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.*;

import java.util.Collection;
import java.util.List;

@Mapper
public interface FlyAttributeMapper extends FlyBasicMapper<FlyAttribute> {

    @Select("select * from fly_attribute a where 1=1 ")
    List<FlyAttribute> selectAllList();

    @Select({"select * from fly_attribute a where 1=1 and a.systemId = #{systemId}"})
    List<FlyAttribute> selectAllBySystemId(@Param("systemId") Integer systemId);

    @Select("select * from fly_attribute a where 1=1 and a.defModelId = #{defModelId} and a.systemId = #{systemId}")
    List<FlyAttribute> selectAllByDefModelIdAndSystemId(@Param("defModelId") Integer defModelId,@Param("systemId") Integer systemId);

    @Select("select * from fly_attribute a where 1=1 and a.modelId = #{modelId} and a.systemId = #{systemId}")
    List<FlyAttribute> selectAllByModelIdAndSystemId(@Param("modelId") Integer modelId,@Param("systemId") Integer systemId);


    @Select({"<script>"+
        "select * from fly_attribute a where 1=1 " +
        "and a.id in "+
        "<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'>"+
        "#{id}"+
        "</foreach>"+
        "</script>"
    })
    List<FlyAttribute> selectAllByIds(@Param("ids")int[] ids);

    @Delete("delete a from fly_attribute a where 1=1 and a.modelId = #{modelId}")
    int deleteByModelId(@Param("modelId") Integer modelId);

    @Delete({"<script>"+
            "delete a from fly_attribute a where 1=1 " +
            "and a.id in "+
            "<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'>"+
            "#{id}"+
            "</foreach>"+
            "</script>"
    })
    int deleteByIds(@Param("ids")int[] ids);

    /**
     * 批量插入（mysql）
     * @param entityList
     * @return
     */
    Integer insertBatchSomeColumn(Collection<FlyAttribute> entityList);


    @Select({"<script>",
            " select *",
            " from fly_attribute a ",
            " where 1=1",
            "<when test='label!=null and label!=\"\"'>",
            "  and a.label like #{label,jdbcType=VARCHAR}",
            "</when>",
            "<when test='name!=null and name!=\"\"'>",
            "  and a.name like #{name,jdbcType=VARCHAR} " +
            "</when>",
            "<when test='fieldName!=null and fieldName!=\"\"'>",
            "  and a.fieldName like #{fieldName,jdbcType=VARCHAR}",
            "</when>",
            " and a.systemId = #{systemId}",
            "</script>"})
    List<FlyAttribute> depository(@Param("label")String label, @Param("name") String name, @Param("fieldName")String fieldName, @Param("systemId") Integer systemId);
}
